<template>
  <section id="features" class="feature-section">
    <div class="container">
      <div class="text-center mb-5" :class="{ 'slide-up visible': isVisible }">
        <h2 class="fw-bold">核心功能</h2>
        <p class="text-muted">为您提供全方位的考研数据服务</p>
      </div>
      <div class="row g-4">
        <div
            v-for="(feature, index) in features"
            :key="feature.title"
            class="col-lg-4 col-md-6"
        >
          <div
              class="feature-card"
              :class="{ 'slide-up visible': isVisible }"
              :style="{ transitionDelay: `${index * 0.2}s` }"
          >
            <div class="feature-icon">
              <i :class="feature.icon"></i>
            </div>
            <h4>{{ feature.title }}</h4>
            <p>{{ feature.description }}</p>
            <router-link :to="feature.link" class="btn btn-outline-primary">了解更多</router-link>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  name: 'FeaturesSection',
  data() {
    return {
      isVisible: false,
      features: [
        {
          icon: 'bi bi-bar-chart-line',
          title: '院校数据分析',
          description: '提供历年分数线、报录比、招生人数等核心数据，帮助您精准选择目标院校。',
          link: '/features/school-data'
        },
        {
          icon: 'bi bi-graph-up',
          title: '智能匹配推荐',
          description: '基于您的成绩、兴趣和职业规划，智能推荐最适合的院校和专业组合。',
          link: '/features/recommendation'
        },
        {
          icon: 'bi bi-calendar-check',
          title: '备考规划系统',
          description: '个性化备考计划，科学安排复习进度，提高备考效率。',
          link: '/features/plan'
        },
        {
          icon: 'bi bi-people',
          title: '学长学姐咨询',
          description: '直通目标院校学长学姐，获取第一手考研经验和内部信息。',
          link: '/features/consult'
        },
        {
          icon: 'bi bi-journal-text',
          title: '真题资料库',
          description: '海量历年真题、专业课资料、复习笔记，助您高效备考。',
          link: '/features/materials'
        },
        {
          icon: 'bi bi-bell',
          title: '实时更新提醒',
          description: '招生简章、调剂信息、分数线公布等重要通知第一时间推送。',
          link: '/features/notifications'
        }
      ]
    }
  },
  methods: {
    checkVisibility() {
      const element = this.$el
      if (element) {
        const elementTop = element.getBoundingClientRect().top
        const windowHeight = window.innerHeight
        if (elementTop < windowHeight - 100) {
          this.isVisible = true
          window.removeEventListener('scroll', this.checkVisibility)
        }
      }
    }
  },
  mounted() {
    window.addEventListener('scroll', this.checkVisibility)
    this.checkVisibility()
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.checkVisibility)
  }
}
</script>

<style scoped>
.feature-section {
  padding: 80px 0;
  background-color: var(--light-color);
}

.feature-card {
  background: white;
  border-radius: 10px;
  padding: 30px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.05);
  height: 100%;
  transition: all 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 30px rgba(0,0,0,0.1);
}

.feature-icon {
  font-size: 50px;
  color: var(--primary-color);
  margin-bottom: 20px;
}

.slide-up {
  opacity: 0;
  transform: translateY(50px);
  transition: all 0.6s ease-out;
}

.slide-up.visible {
  opacity: 1;
  transform: translateY(0);
}
</style>